/*
 * @Author: your name
 * @Date: 2020-08-17 11:35:49
 * @LastEditTime: 2020-08-17 12:05:16
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edio
 * @FilePath: \PipeOneMap_WebClient\src\app\business\home\form-constor\form-control.service.ts
 */
import { Injectable } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';

import { FormBase } from './form-base';
import { FormService } from './form.service';

@Injectable({
  providedIn: 'root'
})
export class FormControlService {

  constructor() { }
  toFormGroup(formItems: FormBase[] ) {
    let group: any = {};

    formItems.forEach(formItem => {
      group[formItem.fieldId] = formItem.required ? new FormControl(formItem.value || '', Validators.required)
                                              : new FormControl(formItem.value || '');
    });
    return new FormGroup(group);
  }
}
